#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_gpio.h"
#include "hi_io.h"
#include "hi_time.h"
#include "hi_adc.h"
#include "iot_errno.h"

#include "hi_wifi_api.h"
#include "lwip/ip_addr.h"
#include "lwip/netifapi.h"
#include "lwip/sockets.h"
#include "lwip/netif.h"
#include "lwip/ip4_addr.h"
#include "lwip/api_shell.h"
#include "wifi_hotspot.h"

#include "wifi_device.h"
#include "wifi_device_config.h"

#include <hi_types_base.h>
#include <hi_i2c.h>
#include <hi_early_debug.h>
#include <hi_stdlib.h>


static char data[128] = "";
extern int connfd;

void *RobotCarTestTask(void* param)
{
    (void)param;
    float cmm = 0.0;
	printf("switch\r\n");
    while (1) {
        //custom((i%11)*100 + 1000);
        GetDistance(&cmm);

        sprintf(data,"{\"cm\":%f}",cmm);

        send(connfd, data, strlen(data), 0);//发送距离到APP
        //printf("\r\n cos = %d  cm =%f\r\n",i,cmm);
        osDelay(25); //延时 250ms
    }
}



void RobotCarDemo(void)
{
    osThreadAttr_t attr;
    attr.name = "RobotCarTestTask";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = 10240;
    attr.priority = 25;

    if (osThreadNew(RobotCarTestTask, NULL, &attr) == NULL) {
        printf("[Ssd1306TestDemo] Falied to create RobotCarTestTask!\n");
    }

}
APP_FEATURE_INIT(RobotCarDemo);


